package com.tjsinfo.tjsoa.vote.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.tjsinfo.tjsoa.vote.bo.ITVoteOpinionBoxBO;
import com.tjsinfo.tjsoa.vote.vo.TVoteOpinionBox;

public class ToOpinionBoxAction extends DispatchAction {
	private ITVoteOpinionBoxBO opinionBoxBo;
	public void setOpinionBoxBo(ITVoteOpinionBoxBO opinionBoxBo) {
		this.opinionBoxBo = opinionBoxBo;
	}

	public ActionForward opinionBoxForm(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
			return mapping.findForward("opinionBoxForm");
	}
	
	public ActionForward opinionBoxMod(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		    String id = request.getParameter("id");
		    
		    TVoteOpinionBox tvob = opinionBoxBo.findById(id);
		    request.setAttribute("tvob", tvob);
		    
			return mapping.findForward("opinionBoxMod");
	}	
	
	public ActionForward opinionBoxCon(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		    String id = request.getParameter("id");
		    
		    TVoteOpinionBox tvob = opinionBoxBo.findById(id);
		    Integer status = tvob.getStatus();
		    if(status.equals(0)){
		    	tvob.setStatus(1);
		    	opinionBoxBo.update(tvob);
		    }
		    TVoteOpinionBox tvob1 = opinionBoxBo.findById(id);
		    request.setAttribute("tvob", tvob1);
		    
			return mapping.findForward("opinionBoxCon");
	}	
	
}
